package everyday;

import org.junit.jupiter.api.Test;

public class T1017 {
    public String baseNeg2(int n) {
        if (n == 0) return "0";
        String res = "";
        int carry = 0;
        while (n != 0 || carry != 0) {
            n += carry;
            carry = (n & 2) >> 1;
            res = Integer.toBinaryString(n / 2 & 1) + Integer.toBinaryString(n & 1) + res;
            n = n >> 2;
        }
        if (res.charAt(0) == '0') return res.substring(1);
        return res;
    }

    @Test
    public void test() {
        System.out.println(baseNeg2(4));
    }
}
